package com.nav.interpreter.brainfuck;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class BrainfuckSourceReader extends BufferedReader {
	private BrainfuckChar next;
	public BrainfuckSourceReader(String name) throws IOException {
		super(new InputStreamReader(new FileInputStream(name)));
		next();
	}
	public boolean hasNext() {
		return next != null;
	}
	public BrainfuckChar next() throws IOException {
		BrainfuckChar ret = next;
		while(true) {
			int i = read();
			if(i < 0) {
				next = null;
				return ret;
			}
			next = BrainfuckChar.getInstance((char)i);
			if(next != null)
				break;
		}
		return ret;
	}
}
